package com.oro.domain;

import static javax.persistence.CascadeType.ALL;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

/**
 * Entity implementation class for Entity: Costo
 * 
 */
@Entity
public class Costo implements Serializable {

	public static final String AUD = "AUD";
	private static final List<String> currencies = new ArrayList<String>() {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		{
			add(AUD);
		}
	};

	private static final long serialVersionUID = 1L;

	public static List<String> getCurrencies() {
		return currencies;
	}

	@ManyToOne
	@JoinTable(name = "costo_corso")
	// Bi-directional
	private Corso course;

	private String currency; // "AUD", "USD"

	@Id
	@GeneratedValue
	private Long id;

	private int maxWeeks;

	private int minWeeks;

	/**
	 * This commission, if populated, will override the course's
	 */
	@OneToOne(cascade = ALL)
	@JoinTable(name = "costo_commissioneretta")
	private Commissione subscriptionCommission;

	private float subscriptionFee;

	/**
	 * This commission, if populated, will override the course's
	 */
	@OneToOne(cascade = ALL)
	@JoinTable(name = "costo_commissioneretta")
	private Commissione tuitionCommission;

	private float weeklyPrice;

	private float weeklyPricePublic;

	public Costo() {
		super();
		subscriptionCommission = new Commissione();
		tuitionCommission = new Commissione();
	}

	public Costo(int min, int max, float price) {
		this();
		setMinWeeks(min);
		setMaxWeeks(max);
		setWeeklyPrice(price);
	}

	public Costo(int min, int max, float price, Corso course) {
		this(min, max, price);
		setCourse(course);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null)
			return false;
		if (!(o instanceof Costo))
			return false;
		if (id != null)
			return id.equals(((Costo) o).getId());
		else
			return minWeeks == ((Costo) o).getMinWeeks()
					&& maxWeeks == ((Costo) o).getMaxWeeks()
					&& weeklyPrice == ((Costo) o).getWeeklyPrice()
					&& course.equals(((Costo) o).getCourse());
	}

	public Corso getCourse() {
		return course;
	}

	public String getCurrency() {
		return currency;
	}

	public Long getId() {
		return id;
	}

	public int getMaxWeeks() {
		return maxWeeks;
	}

	public int getMinWeeks() {
		return minWeeks;
	}

	public Commissione getSubscriptionCommission() {
		return subscriptionCommission;
	}

	public float getSubscriptionFee() {
		return subscriptionFee;
	}

	public Commissione getTuitionCommission() {
		return tuitionCommission;
	}

	public float getWeeklyPrice() {
		return weeklyPrice;
	}

	public float getWeeklyPricePublic() {
		return weeklyPricePublic;
	}

	public void setCourse(Corso course) {
		this.course = course;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setMaxWeeks(int maxWeeks) {
		this.maxWeeks = maxWeeks;
	}

	public void setMinWeeks(int minWeeks) {
		this.minWeeks = minWeeks;
	}

	public void setSubscriptionCommission(Commissione subscriptionCommission) {
		this.subscriptionCommission = subscriptionCommission;
	}

	public void setSubscriptionFee(float subscriptionFee) {
		this.subscriptionFee = subscriptionFee;
	}

	public void setTuitionCommission(Commissione tuitionCommission) {
		this.tuitionCommission = tuitionCommission;
	}

	public void setWeeklyPrice(float weeklyPrice) {
		this.weeklyPrice = weeklyPrice;
	}

	public void setWeeklyPricePublic(float weeklyPricePublic) {
		this.weeklyPricePublic = weeklyPricePublic;
	}

}
